function f_exit()
{   #退出时清理临时文件
    declare file_count sql
    {
        [ -f "${sql_exe_error}" ] && rm -f "${sql_exe_error}"
        [ -S "${gh_socket_file}" -o -f "${gh_socket_file}" ] && rm -f "${gh_socket_file}"
        [ -f "${alter_file_tmp}" ] && rm -f "${alter_file_tmp}"
        [ -f "${alter_file_tmp1}" ] && rm -f "${alter_file_tmp1}"
        [ -f "${alter_file_tmp2}" -a "${execute}x" == "1x" ] && rm -f "${alter_file_tmp2}"
        [ -f "${alter_file_tmp2}" -a "${1}x" == "1x" ] && rm -f "${alter_file_tmp2}"
        [ -f "${alter_file_tmp3}" ] && rm -f "${alter_file_tmp3}"
        [ -f "${res_file}" ] && rm -f "${res_file}"
        [ -f "${max_thread_file}" ] && rm -f "${max_thread_file}"
        [ -f "${has_mdl_lock_file}" ] && rm -f "${has_mdl_lock_file}"
        [ -f "${bug_mark_file}" ] && rm -f "${bug_mark_file}"
        [ -d "${hook_dir}/${mysql_port}" ] && rm -rf "${hook_dir}/${mysql_port}"
        [ -f "${has_max_process_file}" ] && chattr -i ${has_max_process_file} && rm -f "${has_max_process_file}"
        if [ -n "${test_mysql_comm}" ]
        then
            if [ "${1}x" == "1x" ] || [ "${execute_opt}x" == "0x" ] || [ "${execute}x" == "1x" ]
            then
                f_logging "$(eval echo ${log_addr}):REMAIND" "准备清理测试环境'${test_host}:${test_port}:${test_db},${test_db_exe}'" || true
                timeout ${exe_time} ${test_mysql_comm} -NBe "drop database if exists ${test_db_exe};drop database if exists ${test_db};" >/dev/null 2>&1 || f_logging "$(eval echo ${log_addr}):ERROR" "清理测试环境失败'${test_host}:${test_port}:${test_db},${test_db_exe}'" || true
            fi
        fi

        if [ "${1}x" == "1x" ] || [ "${execute_opt}x" == "0x" ] || [ "${execute}x" == "1x" ]
        then
            cron_sql="update ${t_cront_task} set istate=0 where order_id=${user_order_id} and istate = 1;"
            f_exe_sql_to_dbadb "${cron_sql}" "f_exit" || true
        fi

        #针对rename操作, 会生成old_table和new_table的文件
        for ((file_count=0; file_count<=${#osc_run_mark_file_list[@]}; file_count++))
        do
            if [ -f "${osc_run_mark_file_list[${file_count}]}" ]
            then
                chattr -i ${osc_run_mark_file_list[${file_count}]} && rm -f ${osc_run_mark_file_list[${file_count}]}
            fi
        done
        [ -f "${res_log}.back" ] && rm -f "${res_log}.back"
        [ -f "${pause_file_name}" ] && rm -f "${pause_file_name}"
        [ -f "${check_mdl_mark_file}" ] && rm -f "${check_mdl_mark_file}"
        [ -f "${check_connect_file}" ] && rm -f "${check_connect_file}"
        [ -f "${check_thread_file}" ] && rm -f "${check_thread_file}"
        for ((file_count=0; file_count<=${#script_queue_file_list[@]}; file_count++))
        do
            [ -f "${script_queue_file_list[${file_count}]}" ] && rm -f ${script_queue_file_list[${file_count}]}
        done
    } || true

    [ "${1}x" == "-1x" ] && return 0

    if [ "${execute_opt}x" == "0x" ] || [ "${execute}x" == "1x" ] || [ "${1}x" == "1x" ]
    then #释放队列
        order_sql="update ${t_queue_info} set order_id = 0, inip = '', run_state = 0 where mysql_port = ${mysql_port} and db_name = '${mysql_db}' and run_state = 1 and order_id = ${user_order_id};"
        f_exe_sql_to_dbadb "${order_sql}" "f_exit" || true
    fi

    if [ "${1}x" == "1x" ] && [ "${execute_opt}x" == "0x" ]
    then
        order_sql="update ${t_order_info} set progress = '定时任务, 预执行失败' , run_state = -1 where progress = '定时任务, 尚未开始' and order_id = ${user_order_id} and port = ${mysql_port};
            update ${t_cront_task} set istate = 0 where order_id = ${user_order_id};"
        f_exe_sql_to_dbadb "${order_sql}" "f_exit" || true
    fi

    __="delete from ${t_state_task} where order_id = ${user_order_id} and port = ${mysql_port};" #清理库里的临时记录
    [ "$(grep -ic "^alter_table" <<< "${mode_opt}")x" == "1x" ] && f_exe_sql_to_dbadb "${__}" "f_exit" || true
    env="线上环境"

    if [ "${1}x" == "1x" ]
    then
        sql="select group_concat(log_info) from (select log_info,'a' from ${t_global_log}
            where order_id = ${user_order_id} and mysql_port = ${mysql_port} and log_level='错误' and log_info not like '%详情请看%' group by log_info)b group by a"
        #__="$(${mysql_comm_dbadb} -NBe "${sql}" 2>/dev/null|sed -r 's/10\.[0-9.]+[^:]/xxxx/g'|sed 's/"/'\''/g')"
        __="$(${mysql_comm_dbadb} -NBe "${sql}" 2>/dev/null|sed 's/"/'\''/g')"
        [ "${execute_opt}x" == "0x" ] && f_update_onlineddl_state_to_table_info "false" "预执行失败，失败原因:${__}" "${_t_}"

        __="执行失败"
    else
        if [ "${dev_mark}x" == "truex" ]
        then
            env="测试环境"
        fi

        __="执行完成"
    fi

    url="${alert_url}?user=${g_user_name}&type=wx&url=${link_url}"
    if [ "${mode_opt}x" != "crontab_dropx" ]
    then
        if [ "${mode_opt}x" == "alter_tablex" ]
        then
            order_name="改表工单"
        else
            order_name="删表/清表工单"
        fi
        order_show_info="数据库表:${mysql_db} [${_t_list}]"
        info="$(date "+%F %T");${order_name}:${__};工单号:${user_order_id}(${env});端口号:${mysql_port};${order_show_info};这是提示信息, 可以忽略"
        [ "${execute_opt}x" == "1x" ] && { curl  -XGET --data-urlencode "info=${info}" "${url}" || true ;}
    fi
    [ "${1}x" == "0x" ] && exit 0
    [ "${1}x" == "1x" ] && exit 1
    return 0
}
